using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerAnimaition : MonoBehaviour {

    private Rigidbody2D rb;
    private Animator ani;
    private PhysicsCheck physicsCheck;
    private PlayerController playerController;

    private void Awake() {
        rb = GetComponent<Rigidbody2D>();
        ani = GetComponent<Animator>();
        physicsCheck = GetComponent<PhysicsCheck>();
        playerController = GetComponent<PlayerController>();
    }

    void Update() {
        SetAnimaitionStatus();
    }

    private void SetAnimaitionStatus() {  // 设置动画状态机的各种状态，以触发动画的改变
        ani.SetFloat("velocityX", MathF.Abs(rb.velocity.x));
        ani.SetFloat("velocityY", rb.velocity.y);
        ani.SetBool("isGround", physicsCheck.isGround);
        ani.SetBool("isCrouch", playerController.isCrouch);
        ani.SetBool("isAttack", playerController.isAttack);
        ani.SetBool("isWall", physicsCheck.isWall);
        ani.SetBool("isSlide", playerController.isSlide);
        ani.SetBool("isDead", playerController.isDead);
    }

    public void PlayerHurt() {
        ani.SetTrigger("hurt");
    }

    // public void PlayerDie() {
    //     ani.SetBool("isDead", true);
    // }

    public void PlayerAttack() {
        ani.SetTrigger("attack");
    }

}
